# GK7205v300 sample Makefile
PORTING_ROOT_DIR ?= $(shell cd $(CURDIR)/../.. && /bin/pwd)

include $(PORTING_ROOT_DIR)/porting_base.mk

HTTP_SERVER_DIR= $(CURDIR)/http_server
INI_PARSER_DIR=$(CURDIR)/ini_parser
# 默认编译链
CROSS_COMPILE ?= arm-gcc6.3-linux-uclibceabi-

# 交叉编译工具铿
AS			= $(CROSS_COMPILE)as
LD			= $(CROSS_COMPILE)ld
CC			= $(CROSS_COMPILE)gcc
CPP			= $(CC) -E
AR			= $(CROSS_COMPILE)ar
NM			= $(CROSS_COMPILE)nm
STRIP		= $(CROSS_COMPILE)strip
OBJCOPY		= $(CROSS_COMPILE)objcopy

TARGET := sample_avenc
# 添加头文件路径
# INCLUDE := -I $(CURDIR)/include 

# 添加库的查找路径
LDFLAGS := -L  	$(CURDIR)/onvif_lib 
LDFLAGS += -L	$(PORTING_ROOT_DIR)/lib/ 
LDFLAGS += -L 	$(PORTING_ROOT_DIR)/sample/rtsp/lib
# LDFLAGS += -L 	$(CURDIR)/rtsp_lib/lib
LDFLAGS += -L 	$(PORTING_ROOT_DIR)/sample/venc/network_protocol/
LDFLAGS += -L 	$(PORTING_ROOT_DIR)/sample/venc/websocket/lib
LDFLAGS += -L 	$(PORTING_ROOT_DIR)/sample/venc/mp4/lib
LDFLAGS += -L 	$(PORTING_ROOT_DIR)/sample/venc/capture/lib


CFLAGS += $(PORTING_CFLAGS) $(PORTING_LIBS) 
CFLAGS += -I$(CURDIR)/include  -I$(PORTING_ROOT_DIR)/sample/audio -I$(PORTING_ROOT_DIR)/sample/audio/adp \
-I$(PORTING_ROOT_DIR)/sample/common -I$(PORTING_ROOT_DIR)/sample/include -I$(CURDIR)/osd \
-I$(CURDIR)/onvif_lib/include -I$(CURDIR)/onvif_lib/include/openssl	\
-I$(CURDIR)/network -I$(CURDIR)/uart -I$(CURDIR)/websocket/include \
-I$(PORTING_ROOT_DIR)/sample/venc/mp4/include -I$(PORTING_ROOT_DIR)/sample/venc/mp4/src/ \
-I$(PORTING_ROOT_DIR)/sample/venc/conf_time/ -I$(CURDIR)/capture -I$(CURDIR)/capture/include \
-I$(CURDIR)/rtc	\
-I$(PORTING_ROOT_DIR)/sample/rtsp/include -I$(CURDIR)/rtsp_lib/include 

#add http server
# CFLAGS += -I$(HTTP_SERVER_DIR)/src/ -I$(HTTP_SERVER_DIR)/include -I$(HTTP_SERVER_DIR)/cjson -I$(HTTP_SERVER_DIR)/http	\
# -I$(HTTP_SERVER_DIR)/mongoose/ -I$(HTTP_SERVER_DIR)/list/
#add iniparser
CFLAGS += -I$(INI_PARSER_DIR)/src/ 
#add discovery
# CFLAGS += -I$(CURDIR)/discovery_private_devices/ 

#add network_protocol
CFLAGS += -I	$(PORTING_ROOT_DIR)/sample/venc/network_protocol/include

CFLAGS += -Wall -w -fPIC -O2 -g -Os -Wno-date-time -D_GNU_SOURCE  \
-DHI_ACODEC_TYPE_INNER -DHI_VQE_USE_STATIC_MODULE_REGISTER -DHI_AAC_USE_STATIC_MODULE_REGISTER -DHI_AAC_HAVE_SBR_LIB \
-DCHIPSET=gk7205v300  -DWITH_OPENSSL  -DAUTH_ENABLE \
-DSENSOR0_TYPE=BT656_2M_30FPS_8BIT -DRTSP_EN -DOSD_EN -DCVBS_EN 
# -DRTSP_RECORD
# -DDEBUG gk7205v300 -DSENSOR0_TYPE= BT656_2M_30FPS_8BIT SONY_IMX335_MIPI_4M_30FPS_12BIT  -DCVBS_EN
# -DOSD_EN -DAUDIO_EN -DHTTP_CLIENT -DONVIF_EN -DVI_LOW_DELAY  -DOSD_EN -DVPSS_LOW_DELAY  -DAUDIO_EN

# LDFLAGS	+= -lonvif
LDFLAGS	+=  -lrtsp  -lssl  -lcrypto -lnetwork -lcurl -lz -lm -lwebsockets -lmp4v2 -lstdc++ -ljpeg

# $(wildcard *.c)会获取当前目录下所有以.c为扩展名的文件列表
SRCS := $(wildcard ./*.c)
#添加音频
# SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/audio/*.c)
# SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/audio/adp/*.c)
#添加OSD
SRCS += $(wildcard ./osd/*.c)
#添加串口
SRCS += $(wildcard ./network/*.c)
SRCS += $(wildcard ./uart/*.c)

#添加iniparser
SRCS += $(wildcard $(INI_PARSER_DIR)/src/*.c)
#add discovery
# SRCS += $(wildcard $(CURDIR)/discovery_private_devices/*.c) 

#添加mp4
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/mp4/src/*.c)
#添加conf_time
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/conf_time/*.c)
SRCS += $(wildcard $(CURDIR)/capture/*.c)
SRCS += $(wildcard $(CURDIR)/rtc/*.c)

# #查找text中的单词，如果匹配pattern,那么就用replacement的内容替换
#返回：函数返回被替换过后的字符串。
#$(patsubst 原模式， 目标模式， 文件列表)
# $(patsubst <pattern>,<replacement>,<text>) 
OBJS := $(patsubst %.c, %.o, $(SRCS))

.PHONY: all clean

# $@--目标文件，$^--所有的依赖文件，$<--第一个依赖文件

all: $(OBJS)
	$(AT)$(CC) -o $(TARGET) $^ $(CFLAGS)  $(LDFLAGS) 
	# $(SENSOR_LIBS)
	@echo "Complile done."

%.o : %.c
	# make -C $(PORTING_ROOT_DIR)/sample/rtsp/
	$(AT)$(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS) 
rtsp:
	make -C $(PORTING_ROOT_DIR)/sample/rtsp/
common:
	make -C $(PORTING_ROOT_DIR)/sample/common
cp:
	$(STRIP) $(TARGET)
	cp $(TARGET) /nfsdir/$(TARGET) -rf
	cp $(TARGET) /nfsdir/mongoose_web/$(TARGET) -rf
clean:
	$(AT)rm -rf $(OBJS) $(TARGET)  \
	$(CURDIR)/osd/*.o  \
	$(PORTING_ROOT_DIR)/sample/audio/*.o  $(PORTING_ROOT_DIR)/sample/audio/adp/*.o  \
	$(CURDIR)/rtsp_lib/*.a $(CURDIR)/rtsp_lib/*.o \
	$(HTTP_SERVER_DIR)/cjson/*.o $(HTTP_SERVER_DIR)/http/*.o $(HTTP_SERVER_DIR)/list/*.o $(HTTP_SERVER_DIR)/mongoose/*.o $(HTTP_SERVER_DIR)/src/*.o \
	$(INI_PARSER_DIR)/src/*.o	\
	$(CURDIR)/network/*.o	\
	$(CURDIR)/uart/*.o	
